﻿Imports extranet.BE
Imports extranet.BC
Imports System.Collections.Generic
Imports MetodosComuns

Partial Class forum_forum_inicial
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim lstobjBEForum1 As New List(Of BEForum)
        Dim lstobjBEForum2 As New List(Of BEForum)
        Dim i As Integer
        Dim strTela As String = MetodosComuns.GetCurrentPageName()
        Dim objBESeguranca As New BESeguranca
        Dim objBEUsuario As BEUsuario = Session("objBEUsuario")

        If IsNothing(objBEUsuario) Then Response.Redirect(TELA_LOGOUT)
        Session("strTela") = MetodosComuns.GetCurrentPageName()
        If Not IsPostBack Then          ' SEGURANÇA
            objBESeguranca = BCSeguranca.SelecionaPermissoes(objBEUsuario.GrupoAcesso, Session("strTela"))
            If Not objBESeguranca.Autorizado Then Response.Redirect(TELA_LOGOUT)
            Session("objBESeguranca") = objBESeguranca
        Else
            objBESeguranca = Session("objBESeguranca")
        End If


        If objBESeguranca.Escrita Then 'Verificar aki se usuário tem permissao de administrador
            lstobjBEForum1 = BCForum.ListarTodasCategorias 'BCForum.ListaTodasSub()
            If lstobjBEForum1.Count = 0 Then
                lstobjBEForum2 = BCForum.ListarTodasCategorias()
            Else
                lstobjBEForum2 = BCForum.ListarCategoriasSemRepeticao(lstobjBEForum1)
            End If
            lstobjBEForum2 = BCForum.ListarCategoriasSemRepeticao(lstobjBEForum1)

            For i = 0 To lstobjBEForum2.Count - 1
                If lstobjBEForum2(i).Visivel = True Then
                    lstobjBEForum2(i).StrVisibilidade = "Visível"
                Else
                    lstobjBEForum2(i).StrVisibilidade = "Não Visível"
                End If
            Next
            GridView3.Visible = False
            GridView1.DataSource = lstobjBEForum2
            GridView1.DataBind()
        Else
            lstobjBEForum1 = BCForum.ListaSubVisiveis()
            If lstobjBEForum1.Count = 0 Then
                lstobjBEForum2 = BCForum.ListarCategoriasVisiveis()
            Else
                lstobjBEForum2 = BCForum.ListarCategoriasSemRepeticao(lstobjBEForum1)
            End If
            GridView1.Visible = False
            GridView3.DataSource = lstobjBEForum2
            GridView3.DataBind()
        End If
    End Sub

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        For i As Integer = 0 To GridView1.Rows.Count - 1
            Dim gridviewAux As GridView
            Dim lstobjBESubcategoria As New List(Of BESubcategoria)
            Dim j As Integer
            Dim objBESeguranca As New BESeguranca
            Dim objBEUsuario As BEUsuario = Session("objBEUsuario")

            If IsNothing(objBEUsuario) Then Response.Redirect(TELA_LOGOUT)
            Session("strTela") = MetodosComuns.GetCurrentPageName()
            If Not IsPostBack Then          ' SEGURANÇA
                objBESeguranca = BCSeguranca.SelecionaPermissoes(objBEUsuario.GrupoAcesso, Session("strTela"))
                If Not objBESeguranca.Autorizado Then Response.Redirect(TELA_LOGOUT)
                Session("objBESeguranca") = objBESeguranca
            Else
                objBESeguranca = Session("objBESeguranca")
            End If


            gridviewAux = GridView1.Rows(i).FindControl("GridView2")

            If objBESeguranca.Escrita Then 'Verificar aki se usuário tem permissao de administrador
                lstobjBESubcategoria = BCForum.ListaTodasSub(GridView1.DataKeys(i).Value)
                For j = 0 To lstobjBESubcategoria.Count - 1
                    If lstobjBESubcategoria(j).Visivel = True Then
                        lstobjBESubcategoria(j).StrVisibilidade = "Visível"
                    Else
                        lstobjBESubcategoria(j).StrVisibilidade = "Não Visível"
                    End If
                Next
            Else
                lstobjBESubcategoria = BCForum.ListaSubVisiveis(GridView1.DataKeys(i).Value)
                GridView1.Rows(i).FindControl("lnkBtnVisibilidade").Visible = False
                GridView1.Rows(i).FindControl("lnkBtnEditar").Visible = False
                GridView1.Rows(i).FindControl("lnkBtnExcluir").Visible = False
                GridView1.Rows(i).FindControl("lnkBtnAddSubcategoria").Visible = False

                gridviewAux.Columns(3).Visible = False
                gridviewAux.Columns(4).Visible = False
                gridviewAux.Columns(5).Visible = False

                lnkBtnAddCategoria1.Visible = False
            End If
            gridviewAux.DataSource = lstobjBESubcategoria
            gridviewAux.DataBind()
        Next
    End Sub

    Protected Sub GridView3_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView3.DataBound
        For i As Integer = 0 To GridView3.Rows.Count - 1
            Dim gridviewAux As GridView
            Dim lstobjBESubcategoria As New List(Of BESubcategoria)
            gridviewAux = GridView3.Rows(i).FindControl("GridView4")

            lstobjBESubcategoria = BCForum.ListaSubVisiveis(GridView3.DataKeys(i).Value)

            lnkBtnAddCategoria1.Visible = False

            gridviewAux.DataSource = lstobjBESubcategoria
            gridviewAux.DataBind()
        Next
    End Sub

    Protected Sub btnPesquisar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPesquisar.Click
        Session("strFiltro") = txtBusca.Text
        Response.Redirect("forum_inicialPesquisaSimples.aspx")
    End Sub

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Response.Redirect("forum_inicialPesquisaAvancada.aspx")
    End Sub
End Class
